require(reshape2)
require(ggplot2)
save2PDF <- function(pdfPath, myPlot) {
  pdf(pdfPath)
  print(myPlot)
  dev.off()
}

#setwd('/home/song/project/going/mathStatistic/regression/2016/theChinaStudy')
setwd('/home/song/project/mathStatistic/2016/theChinaStudy')


D.raw = read.csv('rawdata.csv', stringsAsFactors = F, header=T, na.strings = "", row.names = 1) #
D.cut = D.raw[,-17] # remove empty column
D.scaled = data.frame(scale(D.cut))
D.rowNameAsVar = data.frame(D.scaled, pos=rownames(D.scaled))
D.long = melt(D.rowNameAsVar)
P.column =
  ggplot(D.long)+
  geom_histogram(aes(x=value, fill=variable))+
  facet_wrap(~variable)+  # multiple plot in one figure
  ggtitle("Histogram of All Variables")+
  xlab("Scaled data")+ylab("Count")+
  theme(legend.position="none")
# save2PDF("quickViewOfData.pdf",P.column)
L.lmResult = lm(X0056F~. , D.scaled)
summary(L.lmResult)

# #-------------- test area -----------------
# P.column = ggplot()+geom_histogram(aes(x=D.scaled[[S.colName]]),binwidth=0.4)
# P.column = ggplot(D.long)+geom_histogram(aes(x=value, fill=factor(variable)),binwidth=0.4)
# P.column = ggplot(D.long)+geom_boxplot(aes(x=factor(variable),y=value))+coord_flip()
# P.column =
#   ggplot(D.long)+
#   geom_density(aes(x=value, colour=variable), alpha=0.1)+
#   facet_wrap(~variable)+
#   ggtitle("Distribution of All Variables")+
#   xlab("scaled data")+ylab("Density")+
#   theme(legend.position="none")
# P.column
# 
# D.tmp = data.frame(D.scaled, pos=rownames(D.scaled))
# D.long = melt(D.tmp)
# # ----------- end test area --------------

